package com.example.q_kang.hhh.home;


import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.example.q_kang.hhh.R;
import com.hjq.toast.ToastUtils;
import com.sskj.base.MVPActivity;
import com.sskj.base.api.SpConfig;
import com.sskj.base.base.App;
import com.sskj.base.bean.JiHuoCommmonBean;
import com.sskj.base.utils.CheckUtil;
import com.sskj.base.utils.ClickUtil;
import com.sskj.base.utils.SPUtils;
import com.sskj.base.view.ToolBarLayout;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @author Hey
 * Create at  2019/04/10
 */
public class TeamJiHuoActivity extends MVPActivity<TeamJiHuoPresenter> {


    @BindView(R.id.toolbar)
    ToolBarLayout toolbar;
    @BindView(R.id.tv_last_jihuo)
    TextView tvLastJiHuo;
    @BindView(R.id.et_mobile)
    EditText etMobile;
    @BindView(R.id.et_code)
    EditText etCode;
    @BindView(R.id.tv_get_code)
    TextView tvGetCode;
    @BindView(R.id.et_pwd)
    EditText etPwd;
    @BindView(R.id.btn_confirm)
    Button btnConfirm;
    @BindView(R.id.btn_send_code)
    Button btnSendCode;
    private int myJiHuo;

    @Override
    public int getLayoutId() {
        return R.layout.activity_team_j_ihuo;
    }

    @Override
    public TeamJiHuoPresenter getPresenter() {
        return new TeamJiHuoPresenter();
    }

    @Override
    public void initView() {
        toolbar.setLeftButtonOnClickListener(view -> finish());
        toolbar.setRightButtonOnClickListener(view -> JiHuoRecordActivity.start(this));
        ClickUtil.click(300, btnSendCode, view -> CodeJiHuoSendActivity.start(this, myJiHuo));
        ClickUtil.click(300, tvGetCode, view -> {
            if (TextUtils.isEmpty(etMobile.getText().toString())) {
                ToastUtils.show(App.INSTANCE.getString(R.string.appJavaTeamJiHuoActivity1));
                return;
            }
            if (!CheckUtil.isMobile(etMobile.getText().toString().trim())) {
                ToastUtils.show(App.INSTANCE.getString(R.string.appJavaTeamJiHuoActivity2));
                return;
            }
            mPresenter.sendCode(etMobile.getText().toString().trim());
        });
        ClickUtil.click(300, btnConfirm, view -> {
            if (TextUtils.isEmpty(etMobile.getText().toString())) {
                ToastUtils.show(App.INSTANCE.getString(R.string.appJavaTeamJiHuoActivity1));
                return;
            }
            if (!CheckUtil.isMobile(etMobile.getText().toString().trim())) {
                ToastUtils.show(App.INSTANCE.getString(R.string.appJavaTeamJiHuoActivity2));
                return;
            }
            if (TextUtils.isEmpty(etCode.getText().toString())) {
                ToastUtils.show(App.INSTANCE.getString(R.string.appJavaTeamJiHuoActivity5));
                return;
            }
            if (TextUtils.isEmpty(etPwd.getText().toString())) {
                ToastUtils.show(App.INSTANCE.getString(R.string.appJavaTeamJiHuoActivity6));
                return;
            }
            mPresenter.jiHuo(etMobile.getText().toString(),
                    etCode.getText().toString(),
                    etPwd.getText().toString());
        });
    }

    @Override
    public void initData() {
        mPresenter.getMyJiHuo();
    }

    public static void start(Context context) {
        Intent intent = new Intent(context, TeamJiHuoActivity.class);
        context.startActivity(intent);
    }

    public void sendCodeSuccess() {
        startTimeDown(tvGetCode);
    }

    public void getJiHuoSuccess(JiHuoCommmonBean data) {
        this.myJiHuo = data.getJhNum();
        tvLastJiHuo.setText(App.INSTANCE.getString(R.string.appJavaTeamJiHuoActivity7) + data.getJhNum() + ")");
    }
}
